﻿using System;
using DevExpress.XtraEditors;
using UniMana.Data;
using UniMana.Utils.Helper;
using UniMana.Utils.Controls;
using UniMana.Utils.Data;
namespace UniMana.Win.Training
{
    public partial class FrmSchedule_SubEdit : DevExpress.XtraEditors.XtraForm
    {
        private bds m_bds = new bds();
        private DBMain m_DBMain = new DBMain();
        private int m_iTraining_SubjectOpenRequestKey;
        private Training_SubjectOpenRequestInfo m_Training_SubjectOpenRequestInfo;
        public FrmSchedule_SubEdit()
        {
            InitializeComponent();
        }

        public FrmSchedule_SubEdit(int _iTraining_SubjectOpenRequestKey)
        {
            InitializeComponent();
            this.m_iTraining_SubjectOpenRequestKey = 
                _iTraining_SubjectOpenRequestKey;
            this.m_Training_SubjectOpenRequestInfo = 
                new Training_SubjectOpenRequestInfo(
                    this.m_iTraining_SubjectOpenRequestKey);
            this.lueTraining_Session.GetData(
                this.m_DBMain.m_DCReadOnly.Training_Sessions);
            this.lueTraining_WeekDay.GetData(
                this.m_DBMain.m_DCReadOnly.Training_WeekDays);
            this.lueTraining_WeekDay.EditValue = 
                this.m_Training_SubjectOpenRequestInfo.Properties.Training_WeekDayKey+1;
            this.lueTraining_Session.EditValue = 
                this.m_Training_SubjectOpenRequestInfo.Properties.Training_SessionKey+1;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if (this.lueTraining_Session.GetIntValue() != -1 && 
                this.lueTraining_WeekDay.GetIntValue() != -1)
            {
                this.m_Training_SubjectOpenRequestInfo.Properties.Training_WeekDayKey = 
                    this.lueTraining_WeekDay.GetIntValue()-1;
                this.m_Training_SubjectOpenRequestInfo.Properties.Training_SessionKey = 
                    this.lueTraining_Session.GetIntValue();
                this.m_Training_SubjectOpenRequestInfo.Save();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                XtraMessageBox.Show("Chưa chọn ngày hoặc ca");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}